<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
		<title>生命体征检测云平台</title>
		<link rel="shortcut icon" href="static/logo.ico" />
		<link rel="stylesheet" href="static/css/index.css" />
		<link rel="stylesheet" href="static/layui/css/layui.css" />
		<script type="text/javascript" src="static/js/jquery.min.js"></script>
		<script src="static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="static/js/vue.js"></script>
		<script type="text/javascript" src="static/js/axios.min.js"></script>
		<style>
			html,
			body,
			#container {
				height: 100%;
				width: 100%;
			}

			.container {
				height: auto;
				width: 100%;
			}

			.container 2 {
				height: auto;
				width: 100%;
			}

			.collision-btn.disable {
				background-image: none;
				color: lightgrey;
				border-color: lightgrey;
				cursor: not-allowed;
			}

			.collision-btn.disable:hover {
				background-color: #fff;
				border-color: lightgrey;
			}

			.input-card .btn {
				margin-right: .8rem;
			}

			.amap-marker {
				opacity: 0.01;
			}

			.nav-right {
				top: 1.5rem !important;
			}

			.info {
				z-index: 999 !important;
			}

			.layui-form-label {
				width: 110px;
				font-size: 14px !important;
			}

			::-webkit-input-placeholder {
				/*Webkit browsers*/
				color: #999;
				font-size: 13px;
			}

			:-moz-placeholder {
				/*Mozilla Firefox 4 to 8*/
				color: #999;
				font-size: 13px;
			}

			::moz-placeholder {
				/*Mozilla Firefox 19+*/
				color: #999;
				font-size: 13px;
			}

			:-ms-input-placeholder {
				/*Internet Explorer 10+*/
				color: #999;
				font-size: 13px;
			}

			.layui-form-pane .layui-input {
				height: 38px !important;
			}

			.layui-form-checked span,
			.layui-form-checked:hover span {
				background-color: #063683;
			}

			.layui-form-checked i,
			.layui-form-checked:hover i {
				color: #063683;
			}

			.layui-form-checkbox i {
				height: 30px;
			}

			.layui-form-onswitch {
				border-color: #063683;
				background-color: #063683;
			}

			.layui-form-label {
				width: 116px;
			}

			.layui-select-title {
				position: absolute;
			}
		</style>
		<script>
			layui.use(['form', 'layedit', 'laydate', 'dropdown'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate,
					dropdown = layui.dropdown;
				dropdown.on('click(docDemoMenu1)', function(options) {
					var othis = $(this); //当前菜单列表的 DOM 对象
					console.log(options.url)

				});
				var rloginName = localStorage.loginName;
				$.ajax({
					url: url + "/user/equipment/infoList?userId=" + rloginName,
					dataType: 'json',
					type: 'get',
					async: false,
					success: function(res) {
						$.each(res, function(index, item) {
							var option;
							if (item.equName != null || item.equName !=
								"" || item.equName != "null") {
								option = new Option(item.equName, item.equName);
							}
							$('#einfo').append(option); // 下拉菜单里添加元素
						}); +
						form.render("select");
						//重新渲染 固定写法
					}
				});
				//时间范围
				laydate.render({
					elem: '#times',
					type: 'time',
					range: true
				});

				form.on('switch(switchbxcjjg)', function(data) {
					if (this.checked == true) {
						$('#bxcjjg').val(1);
					} else {
						$('#bxcjjg').val(0);
					}
					// layer.tips('温馨提示：授权社区管理员是否可以查看定位地址信息', data.othis)
				});

				form.on('switch(switchbg)', function(data) {
					if (this.checked == true) {
						$('#sbgg').val(1);
					} else {
						$('#sbgg').val(0);
					}
					// layer.tips('温馨提示：授权社区管理员是否可以查看定位地址信息', data.othis)
				});
				var bedtask =JSON.parse(localStorage.bedtask);
				// let jjlxrjosns=localStorage.bedtask;
				// if (jjlxrjosns.length > 0) {
				// 	let jjlxrdata =JSON.parse(jjlxrjosns);
				// 	if (jjlxrdata.length>0) {
				// 		bedtask = jjlxrdata;
				// 	}	
				// }
				console.log(bedtask)
				if (!jQuery.isEmptyObject(bedtask)) {
					$('#ids').val(bedtask.id);
					$('#times').val(bedtask.startTime + ':00' + ' - ' + bedtask.endTime + ':00')
					$("#einfo option[value='" + bedtask.seqId + "']").attr("selected", "selected");
					var isWeekdaydata = '';
					var isWeekdays = bedtask.isWeekday.search(",")
					if (isWeekdays != -1) {
						isWeekdaydata = bedtask.isWeekday.split(',');
						var unitType = [];
						unitType = isWeekdaydata;
						for (var j = 0; j < unitType.length; j++) {
							var unitTypeCheckbox = $("input[name='jctime']");
							for (var i = 0; i < unitTypeCheckbox.length; i++) {
								if (unitTypeCheckbox[i].title == unitType[j]) {
									unitTypeCheckbox[i].checked = true;
								}
							}
						}
					} else {
						var isWeekday =bedtask.isWeekday;
						var unitTypeCheckbox = $("input[name='jctime']");
						for (var i = 0; i < unitTypeCheckbox.length; i++) {
							if (unitTypeCheckbox[i].title==isWeekday) {
								unitTypeCheckbox[i].checked = true;
							} 
						}
					}
					if (bedtask.isopen == true) {
					        $("#iscaijijiange").attr("checked", "checked");
					} else {
					        $("#iscaijijiange").removeAttr('checked');
					}
					
					if (bedtask.shebeibeiguang == true) {
					        $("#shebeibeiguang").attr("checked", "checked");
					} else {
					        $("#shebeibeiguang").removeAttr('checked');
					}
					
				} else {
				
				layer.msg('参数错误！', {
					time: 2000,
					end: function() {
						location.href = 'bed_monitoring_list.html'
					}
				})
				}
				form.render();
			});
		</script>
	</head>
	<body>
		<div id="app">
			<input  type="hidden" value="" id="ids"/>
			<div style="margin-top: 70px;background-color: #e5e5e5;"></div>
			<div class="layui-panel" style="float: left; width: 10% !important;" id="pnav">

			</div>
			<div class="container" style="width: 90% !important; float: right;padding-left: 30px;">
				<div class="layui-fluid">
					<fieldset class="layui-elem-field layui-field-title">
						<legend>在床监测任务</legend>
					</fieldset>
					<div class="layui-form">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">测量时间:</label>
								<div class="layui-input-inline">
									<input type="text" class="layui-input" id="times" placeholder=" - ">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">测量时间:</label>
								<div class="layui-input-block">
									<input type="checkbox" name="jctime" value="周一" title="周一">
									<input type="checkbox" name="jctime" value="周二" title="周二">
									<input type="checkbox" name="jctime" value="周三" title="周三">
									<input type="checkbox" name="jctime" value="周四" title="周四">
									<input type="checkbox" name="jctime" value="周五" title="周五">
									<input type="checkbox" name="jctime" value="周六" title="周六">
									<input type="checkbox" name="jctime" value="周日" title="周日">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">设备选择</label>
							<div class="layui-input-inline">
								<select name="interest" id="einfo">
									<option value="">请选择设备</option>
								</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">波形采集间隔</label>
							<div class="layui-input-block">
								<input type="hidden" value="" id="bxcjjg" />
								<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchbxcjjg"
									lay-text="开|关" id="iscaijijiange">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">设备背光</label>
							<div class="layui-input-block">
								<input type="hidden" value="" id="sbgg" />
								<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchbg"
									lay-text="开|关"  id="shebeibeiguang">
							</div>
						</div>
						<hr />
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button type="submit" class="layui-btn met04" lay-submit="" lay-filter="demo1"
								v-on:click="insertSq">立即修改</button>
							<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
						</div>
					</div>
				</div>
			</div>
			<div class="info">
				<div class="nav-left">
					<a class="login"></a>
					<a class="hometext" href="index.html" v-if="uInfoData.loginType !=1">首页</a>
					<a class="hometext" href="home.html" v-if="uInfoData.loginType == 1">首页</a>
				</div>
				<div class="nav-right">
					<ul>
						<li><a href="monitoring.html" v-if="uInfoData.loginType !=1">监测</a></li>
						<li><a href="historical_data.html" v-if="uInfoData.loginType !=1">历史数据</a></li>
						<li><a href="historical_info.html" v-if="uInfoData.loginType == 1">历史数据</a></li>
						<li><a href="call_p.html">离床报警</a></li>
						<li><a href="#">康养中心</a></li>
						<li><a href="#">中医问诊</a></li>
					</ul>
				</div>
				<div class="userinfo" id="userinfo">
					<img src="static/image/user.png" />
					<!-- <div class="red-dot"></div> -->
					<ul class="user_dropdown">
						<li class="dropdown_item user_ctrl">
							<div class="nickname">{{uInfoData.userName}}</div>
							<div class="sign_out">退出</div>
						</li>
						<li class="dropdown_item msg_item">
							<a href="user.html" target="_blank">
								<span>个人中心</span>
							</a>
						</li>
						<li class="dropdown_item msg_item">
							<a href="my_message.html" target="_blank">
								<span>我的消息</span>
								<span class="msg_unread unread_count show">5</span>
							</a>
						</li>
						<li class="dropdown_item">
							<a href="equipment.html">
								<span>设备</span>
							</a>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="static/js/config.js"></script>
		<script>
			$(function() {
				$("#pnav").load("public_navigation.html");
				$(".sign_out").click(function() {
					localStorage.clear();
					window.location = 'login.html'
				});
			});
			var vm = new Vue({
				el: '#app', //设置当前vue对象可以操作数据的范围,注意不要把vue对象绑定到body中，因为这样，vue需要控制整个页面的内容，效率太低了
				data: {
					uInfoData: []
				},
				ready: function() {
					// this.getdata();
				},
				created: function() {
					this.getdata();
				},
				methods: {
					getdata: function() {
						var rloginName = localStorage.loginName;
						console.log(rloginName);
						if (rloginName == '' || rloginName == 'null' || rloginName == undefined) {
							layer.msg('登录过期或者无权访问！', {
								time: 1000,
								end: function() {
									location.href = 'login.html'
								}
							})
						} else {
							axios({
									method: 'GET',
									url: url + "/user/userInfo/lquserOwnInfo?phoneNum=" + rloginName,
									data: {}
								})
								.then(function(response) {
									console.log(response)
									vm.uInfoData = response.data;
								})
						}
					},
					insertSq: function() {
						var arr = [];
						$.each($('input:checkbox:checked'), function() {
							arr.push($(this).val());
						});
						var ids = $('#ids').val();
						var timess = $('#times').val().split('-');
						var arron = arr.toString().split(',on');
						var jctimes;
						var einfo = $('#einfo').val();
						var bxcjjg = $('#bxcjjg').val();
						var sbgg = $('#sbgg').val();
						var caijitime = "15";
						if (arron.length >= 3) {
							jctimes = arron[0];
							
							console.log(arron);
						} else {
							jctimes = arr.toString();
						}
						console.log(timess);
						console.log(jctimes);
						console.log(einfo);
						console.log(bxcjjg);
						console.log(sbgg);
						var rloginName = localStorage.loginName;
						let data = new FormData();
						data.append('id',ids)
						data.append('equId', einfo);
						data.append('beginTime', timess[0].trim().substr(0, 5));
						data.append('endTime', timess[1].trim().substr(0, 5));
						data.append('jianceWeeks', jctimes);
						data.append('iscaijijiange', '30');
						data.append('caijitime', '5');
						data.append('shebeibeiguang', sbgg);
						data.append('isopen', 1);
						data.append('familyId', "");
						data.append('userPhone', rloginName);
						console.log(timess[0].trim().substr(0, 5));
						console.log(timess[1].trim().substr(0, 5));
						if (data == "undefined" || data == null || data == "") {
							layer.msg('请选择相关选项，相关选项不能为空！')
						} else {
							axios({
									method: 'POST',
									url: url + "/custom/usettings/updateLxtimes",
									data: data //JSON.parse(JSON.stringify(sqInfo))
								})
								.then(function(response) {
									var data = response.data;
									var message = response.data.message;
									if (data.code == 0) {
										localStorage["bedtask"] = '';
										layer.msg(message, {
											time: 2000,
											end: function() {
												location.href = 'bed_monitoring_list.html'
											}
										})
									} else {
										layer.msg(message);
									}
								})
						}
					}
				}
			})
		</script>
	</body>
</html>
